package com.zerdoor.controller;

import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.ArbitrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Project: acgplat
 * Module ID: 005
 * Comments: 仲裁管理
 * JDK version used: JDK1.7
 * Namespace: controller
 * Author：xiaoji
 * Create Date：2014-11-24
 * Modified By：   <修改人中文名或拼音缩写>
 * Modified Date:  <修改日期，格式:YYYY-MM-DD>
 * Why & What is modified  <修改原因描述>
 * Version:                  <版本号>
 */
@Controller
@RequestMapping("arbitration")
public class ArbitrationController {

    @Autowired
    private ArbitrationService arbitrationService;

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(){return "/arbitration/view";}

    /**
     * 获取仲裁数据
     * @param request
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping(value = "/view",method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> view(HttpServletRequest request,int page,int rows){
        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        result.put("arbitrateStatus",request.getParameter("arbitrateStatus"));
        result.put("applyReason",request.getParameter("applyReason"));
        List<Map<String, Object>> list = arbitrationService.getArbitrationInfo(result);
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 获取仲裁论述记录
     * @param id 仲裁编号
     * @return
     */
    @RequestMapping(value = "/discuss",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> discuss(int id){
        Map<String, Object> result = new HashMap<String, Object>();
        List<Map<String, Object>> list = arbitrationService.getItemDiscussByArbitrateId(id);
        result.put("list", list);
        return result;
    }

    /**
     * 仲裁
     * @return
     */
    @RequestMapping(value = "/examine",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> examine(int id,HttpServletRequest request){
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result.put("arbitrateId",id);
            result.put("result",request.getParameter("result"));
            arbitrationService.updateArbitrateResultById(result);
        } catch (Exception e) {
            result.put("errormsg","仲裁失败");
        }
        return result;
    }

}
